package cn.hebutrun.oulabot.common.util;

import lombok.experimental.UtilityClass;

import java.util.Random;
import java.util.UUID;

/**
 * Id工具类
 *
 * @author zhaolong
 * @since 2022-03-04
 */
@UtilityClass
public class IDUtil {
  /**
   * 生成随机UUID
   *
   * @return java.lang.String
   * @date 2022/3/4
   * @author zhaolong
   */
  public String getRandomUUID() {
    return UUID.randomUUID().toString().replaceAll("-", "");
  }

//  public String getRandomKsuId() {
//    Ksuid ksuid = KsuidCreator.getKsuid();
//    return ksuid.toString();
//  }

  /**
   * 生成随机数
   *
   * @param length 随机数长度
   * @return java.lang.String
   * @date 2022/3/4
   * @author zhaolong
   */
  public static String getRandomNumber(int length) {
    StringBuilder res = new StringBuilder();
    Random random = new Random();
    for (int i = 0; i < length; i++) {
      res.append(random.nextInt(10));
    }
    return res.toString();
  }

  /**
   * 获取随机用户名
   *
   * @return java.lang.String
   * @date 2022/3/4
   * @author zhaolong
   */
  public static String getRandomUserNickName() {
    return "用户" + getRandomNumber(10);
  }

  public static String getRandomTableId(Class<?> clazz) {
    return clazz.getSimpleName() + "-" + getRandomUUID();
  }
}
